//
//  RXDAboutController.m
//  WaywardPoint_Code
//
//  Created by 韩盼盼 on 15/11/23.
//  Copyright © 2015年 易网新科技. All rights reserved.
//

#import "RXDAboutController.h"

#import "PrivacyController.h"

@interface RXDAboutController ()<UIWebViewDelegate>

@property (strong, nonatomic) UIWebView *browseWeb;


@property(nonatomic,strong)PrivacyController *privacyVc;
@end

@implementation RXDAboutController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed=YES;
    }
    return self;
}

-(PrivacyController *)privacyVc
{
    if (!_privacyVc) {
        _privacyVc=[[PrivacyController alloc]init ];
    }
    return _privacyVc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"关于我们";
    
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
    self.browseWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, kScreenWidth, kScreenHeight)];
    [self.view addSubview:self.browseWeb];
    
    NSURL *url=[NSURL URLWithString:@"http://www.mrbang.com.cn/aboutus.php"];
    [self.browseWeb loadRequest:[NSURLRequest requestWithURL:url]];
    //此处是处理网页黑条条的状况
    self.browseWeb.opaque = NO;
    self.browseWeb.backgroundColor = [UIColor clearColor];
    [self.browseWeb setScalesPageToFit:NO];
    self.browseWeb.delegate = self;
    
    //下拉刷新
    [self PullSownRefresh];

}


/**
 *  下拉刷新
 */
- (void) PullSownRefresh
{
    __unsafe_unretained UIWebView *webView = self.browseWeb;
    webView.delegate = self;
    
    __unsafe_unretained UIScrollView *scrollView = self.browseWeb.scrollView;
    
    // 添加下拉刷新控件
    scrollView.header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [webView reload];
        
    }];
    
    // 如果是上拉刷新，就以此类推
}

#pragma mark 设置UIWebView
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    NSLog(@"url为%@",url);
    
    BOOL returnValue = YES;
    
    if([[url absoluteString] containsString:@"http://www.mrbang.com.cn/service.php"])
    {
        
      self.privacyVc.modalPresentationStyle=UIModalPresentationFullScreen;
      self.privacyVc.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;//UIModalTransitionStyleCrossDissolve,UIModalTransitionStylePartialCurl
        [self presentViewController:self.privacyVc animated:YES completion:nil];
        
        returnValue =  NO;
    }
    return returnValue;
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    [self.browseWeb.scrollView.header endRefreshing];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    [self.browseWeb.scrollView.header endRefreshing];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
@end
